package com.example.campus.api_controller.shiro;


import com.example.campus.dao.model.shiro.Permission;
import com.example.campus.dao.table_gateway.shiro.PermissionMapper;
import com.example.campus.page_controller.dto.ResponseResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

import static com.example.campus.common.BusinessConstants.ADMIN_API_BASE;

@RestController
@RequestMapping(ADMIN_API_BASE + "/permissions")
public class PermissionController {
    @Autowired
    PermissionMapper permissionMapper;

    @PostMapping
    public ResponseResult<String> addPermission(@RequestBody Permission permission) {
        permissionMapper.addPermission(permission);

        return ResponseResult.ok();
    }

    @GetMapping
    public ResponseResult<Set<Permission>> getAllPermissions() {
        var permissions = permissionMapper.getAllPermissions();
         return ResponseResult.ok(permissions);
    }
    @GetMapping("{id}")
    public  ResponseResult<Permission> getActivityById(@PathVariable("id")long id){
        var permission = permissionMapper.getPermissionById(id);
        return ResponseResult.ok(permission);
    }

    @PutMapping
    public ResponseResult<String> updatePermissionById(@Valid @RequestBody Permission permission) {
        permissionMapper.updatePermission(permission);

        return ResponseResult.ok();
    }

    @DeleteMapping("{id}")
    public ResponseResult<String> deletePermissionById(@PathVariable("id")long id){
        permissionMapper.deletePermissionById(id);
        return ResponseResult.ok();
    }
}
